package com.lilihub.miaosha.service;

import com.lilihub.miaosha.dao.GoodsDao;
import com.lilihub.miaosha.domain.Goods;
import com.lilihub.miaosha.domain.MiaoshaGoods;
import com.lilihub.miaosha.redis.GoodKey;
import com.lilihub.miaosha.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @BelongsProject: miaosha
 * @BelongsPackage: com.lilihub.miaosha.service
 * @Author: LiYing
 * @CreateTime: 2021-04-26 20:30
 * @Description:
 */

@Service
public class GoodsService {

    @Autowired
    private GoodsDao goodsDao;


    public List<GoodsVo> getGoodsVoList(){

        List<GoodsVo> goodsVoList = goodsDao.getGoodsVoList();


        return goodsVoList;
    }


    public GoodsVo getGoodsByGoodsId(Long goodsId) {
        return goodsDao.getGoodsByGoodsId(goodsId);


    }

    //减库存
    public boolean reduceStock(GoodsVo goods) {

        MiaoshaGoods g = new MiaoshaGoods();
        g.setGoodsId(goods.getId());
        int ret = goodsDao.reduceStock(g);  //1

        return ret > 0;


    }

    public void resetStock(List<GoodsVo> goodsVoList) {

        for (GoodsVo goodsVo : goodsVoList){
            goodsVo.setStockCount(10);
            goodsDao.resetStock(goodsVo);
        }


    }
}
